var fileSystemObject = new ActiveXObject("Scripting.FileSystemObject");
var adoStream;



//判断是否为空
function isUseful(str){
	if (str == null || str.length == 0 || "null" == str || "undefined" == str){
		return false;
	}
	return true;
}
//获取XmlHttpRequest
function getXMLHttpRequest(){
	var XMLHttpRequest = null;
	if (typeof ActiveXObject != "undefined") {
		var aVersions = ["Microsoft.XMLHTTP", "Msxml2.XMLHttp.6.0", "Msxml2.XMLHttp.5.0", "Msxml2.XMLHttp.4.0", "Msxml2.XMLHttp.3.0"];
		for (var i = 0; i < aVersions.length; i++) {
			try {XMLHttpRequest = new ActiveXObject(aVersions[i]);}catch (ex) {}//注释：不能alert循环的创建的
		}
	} else if (typeof XMLHttpRequest != "undefined"){
		XMLHttpRequest = new XMLHttpRequest();
	}
			
		return XMLHttpRequest;
}


var Microsoft_Scan = {
	// 扫描信息图片路径数据存放集合
	scanImgPath:"",
	scanOpenStatus:false,
	// 开启扫描仪
	openScaner : function() {
		//扫描类型
		var scanType=$("#ScanerSelect").val();
		
		//alert(scanType);
		
		var scaner = ocx;
		
		//扫描仪6240s和平板XT3500的DSMode为9
		if(scanType=='Microtek_6240s' || scanType=='Microtek_XT3500'){
			scaner.DSMode(9);
		//告诉扫描仪S8090的DSMode为8
		}else if(scanType=='Microtek_S8090'){
			scaner.DSMode(8);
		}else{
			scaner.DSMode(0);
		}
		//Long IsScannerOpen()
		//说明：
		//返回值
		//1：扫描仪已打开。
		//0：扫描仪未打开。
		var openStatus = scaner.openScanner();
		if (openStatus != 1) {
			var errorCode = scaner.GetErrorCode();
			this.scanOpenStatus=false;
			layer.alert("扫描仪开启失败!错误代码:" + errorCode,{icon:0});
		}
	
		
		scaner.SetImageName(this.tempImgFile, "0", 1, 7);
		// 去钉孔
		scaner.PunchHoleRemoval(1);
		// 自动纠偏
		scaner.AutoDeskew(1);
		// 黑边补白
		scaner.BlackBorderRemoval(1);// 注释：默认黑边补白
		// 文件格式,可以为下面的几个值:
		// 0:bmp
		// 1:jpg
		// 2.单页tif
		// 3.多页tif
		// 4.单页pdf
		// 5.多页pdf
		// 6.可检索的单页pdf，需要支持OCR识别。
		// 7.可检索的多页pdf，需要支持OCR识别。
		//scaner.ImageFormat = 1;
		// 注释：add at 2015-12-09，否则上传bmp格式太大，上传不了
		scaner.ImageFormat = 2;//jpg  0 bmp 2 tif 3 multitif 4 pdf 5 multipdf
		//scaner.CompressionRate = 20;//注释：压缩质量
		scaner.TiffCompressType = 1; //注释：Tiff压缩  1 JPG压缩  2 G4压缩
		//分辨率
		scaner.ScanResolution =  200;
		// 扫描仪类型
		// 0 Flatbed 平板扫描仪
		// 1 ADF
		// 2 ADF duplex
		var scanType=$("#ScanerSelect").val();
		// 扫描仪类型
		// 0 Flatbed 平板扫描仪
		// 1 ADF
		// 2 ADF duplex
		if(scanType=='Microtek_6240s' || scanType=='Microtek_S8090' ){
			scaner.ScanSourceType = 1;
			scaner.SetScanImageLayout(0,0,9.39,12.69);//A4
			scaner.SetScanThreshold(130);
		//0 Flatbed 平板扫描仪	
		}else if(scanType=='Microtek_XT3500'){
			scaner.ScanSourceType = 0;
			scaner.SetScanImageLayout(0,0,9.39,12.69);//A4
			scaner.SetScanThreshold(130);
		}else{
			scaner.ScanSourceType = 1;
		}
		
		
		
	},
	// 关闭扫描仪
	closeScaner : function() {
		var scaner = ocx;
		scaner.CancelXfers();
		scaner.CloseScanner();
	},
	// 打开UI界面设置扫描仪
	settingScaner : function() {
		var scaner = ocx;
		var scanType=$("#ScanerSelect").val();
		//扫描仪6240s和平板XT3500的DSMode为9
		if(scanType=='Microtek_6240s' || scanType=='Microtek_XT3500'){
			scaner.DSMode(9);
		//告诉扫描仪S8090的DSMode为8
		}else if(scanType=='Microtek_S8090'){
			scaner.DSMode(8);
		}else{
			scaner.DSMode(0);
		}
		var openStatus = scaner.openScanner();
		scaner.ShowUISettings();
	},
	// 单扫
	startScan : function(scanType) {
		var scaner = ocx;
		var scanStatus=0;
		// 单扫
		if (scanType == 1) {
			scanStatus=scaner.Scan(1, 0);
		//连扫
		} else {
			scanStatus=scaner.Scan(-1, 0);
		}
		return scanStatus;

	},
	// 取消扫描
	cancleScan : function() {
		var scaner = ocx;
		scaner.CancelXfers();
	},
	//上传本地扫描图片到服务器
	uploadLocalImg:function(bSuccess){
		var scaner = ocx;
		if (bSuccess == 1){
			//获取本地扫描图片路径
			var imagePath = scaner.GetCurrentScanImagePath();
			//alert("扫描图片路径:"+imagePath);
			var result = uploadPhotoImg(imagePath);
			//alert(result.fileName);
	
			if(result.ret=="success"){
				//this.scanImgArr.push(result.fileName);
				if(isUseful(result.fileName)){
					var basePath=$("#basePath").val();
					var firstGuid=$("#firstGuid").val();
					var picHostPath = $("#picHostPath").val();
					var scanFileSize=$("#scanFileSize").val();
					scanFileSize=parseInt(scanFileSize)+2;
					$.ajax({
						type:"post",
						url:basePath+"/scan/uploadScanImgs",
						data:{firstGuid:firstGuid,scanImage:result.fileName},
						success:function(data){
							//Microsoft_Scan.scanImgArr=[];
							 if(data.success){
								 var scanFile=data.data[0];
								 var url=picHostPath+scanFile.fileUrl+scanFile.fileName;
								// layer.alert("li"+scanFileSize,{icon:1});
								//alert(url+"fileHash="+scanFile.fileHash+"--fileName="+scanFile.fileName+"--fileUrl="+scanFile.fileUrl);
								 var html="<li  fileUrl='"+scanFile.fileUrl+"' fileName='"+scanFile.fileName+"' fileHash='"+scanFile.fileHash+"' >"+
											"<a id='li"+scanFileSize+"' fileUrl='"+scanFile.fileUrl+"' fileName='"+scanFile.fileName+"' class='imgActive' href='#' onclick='test(this)'>"+
											"<span class='close' onclick='del(this)'>x</span>" +
											"<img src='"+url+"' alt='' />"+
											"</a>"
										"</li>";
								$("#MrDocViewOrBoardUl").prepend(html);
								//alert($("#MrDocViewOrBoardUl").html());
								$("#scanFileSize").val(scanFileSize);
							 }else{
								 layer.alert(data.msg,{icon:1});
							 }
						}
					});
				}
			}
		}else{
			scaner.CancelXfers();
			layer.alert("此页文件扫描未成功，请重新扫描！",{icon:0});
		}
	},
	// 扫描临时文件生成路径
	tempImgFile : "D:\\MrLocal",
	// 删除扫描生成临时文件夹内容
	deleteTempImgs : function() {
		var fileSystemObject = new ActiveXObject("Scripting.FileSystemObject");
		var fileSystem = fileSystemObject.GetFolder(this.tempImgFile);
		var enumFiles = new Enumerator(fileSystem.files);
		for (; !enumFiles.atEnd(); enumFiles.moveNext()) {
			enumFiles.item().Delete();
		}
	}
}

//扫描
function scan(scanType){
	//1.删除上次扫描生成的临时文件
	Microsoft_Scan.deleteTempImgs();
	/*//清空存放扫描信息数组
	Microsoft_Scan.scanImgArr=[];*/
	//2.开启扫描仪
	//if(!Microsoft_Scan.scanOpenStatus){
		if(parseInt(ocx.getState)<4){
			Microsoft_Scan.openScaner();
		}
		
		//alert(ocx.getState);
		
	//}
	
	//3.配置扫描仪
	//Microsoft_Scan.init();
	//4.开始扫描
     Microsoft_Scan.startScan(scanType);
     
     Microsoft_Scan.closeScaner();
	//扫描成功为1
/*	if(scanStatus==1){
		if(Microsoft_Scan.scanImgArr.length>0){
			var basePath=$("#basePath").val();
			var firstGuid=$("#firstGuid").val();
			console.log(Microsoft_Scan.scanImgArr.toString());

		  
			$.ajax({
				type:"post",
				url:basePath+"/scan/uploadScanImgs",
				data:{firstGuid:firstGuid,scanImageList:Microsoft_Scan.scanImgArr.toString()},
				success:function(data){
					Microsoft_Scan.scanImgArr=[];
					 if(data.success){

						window.location.href=basePath+"/scan/searchScan?firstGuid="+firstGuid;
					 }else{
						 alert(data.msg);
					 }
				}
			});
			Microsoft_Scan.scanImgArr=[];
			
		}else{
			Microsoft_Scan.scanImgArr=[];
			alert("扫描数据为空,请重新扫描!");
		}
		
	}else{
		alert("扫描失败!错误代码:+"+ocx.GetErrorCode());
	}*/
}



//将临时文件上传至服务器
function uploadPhotoImg(imagePath){
	var basePath=$("#basePath").val();
	var firstGuid=$("#firstGuid").val();
	var mrId = $("#mrId").val();
	//var fileName = imagePath
			
	adoStream = new ActiveXObject("ADODB.Stream");
	adoStream.Mode = 3;//read write
			
	adoStream.Open();
	adoStream.Type = 1;
		   	
	var fileType = imagePath.substring(imagePath.lastIndexOf(".")+1);
	var upOneURL = basePath+"/upload/uploadLocalImg";
	adohttp = getXMLHttpRequest();
	adohttp.open('post', upOneURL, false);
	adohttp.setRequestHeader('-fileType',fileType);
	adohttp.setRequestHeader('-firstGuid',firstGuid);
	adohttp.setRequestHeader('-mrId',mrId);
	
			
			
	adohttp.setRequestHeader('-pageOneLocalPath',imagePath.replace(/\\/g,"/"));
	adohttp.setRequestHeader('Content-Type', 'application/x- www-form-urlencoded');

		   	
	adoStream.LoadFromFile(imagePath);
			
			
	var fileSize = fileSystemObject.GetFile(imagePath).Size;
	var adoStreamSize = adoStream.Size;
			
	if (fileSize != adoStreamSize || fileSize < 3584 || adoStreamSize < 3584){
		adoStream.Close();////
		adoStream = null;
		adohttp = null;
		return "noUp";
	}
			
	adohttp.setRequestHeader("Content-Length",adoStream.Size);
			
	adohttp.send(adoStream.Read(adoStream.Size));
	//返回数据
	var result = JSON.parse(adohttp.responseText);
		   
		   	
	adoStream.Close();////
	adoStream = null;
		   	
	adohttp = null;
		   	
	return result;
}


/*var fileSystemObject = new ActiveXObject("Scripting.FileSystemObject");
var adoStream;



//判断是否为空
function isUseful(str){
	if (str == null || str.length == 0 || "null" == str || "undefined" == str){
		return false;
	}
	return true;
}
//获取XmlHttpRequest
function getXMLHttpRequest(){
	var XMLHttpRequest = null;
	if (typeof ActiveXObject != "undefined") {
		var aVersions = ["Microsoft.XMLHTTP", "Msxml2.XMLHttp.6.0", "Msxml2.XMLHttp.5.0", "Msxml2.XMLHttp.4.0", "Msxml2.XMLHttp.3.0"];
		for (var i = 0; i < aVersions.length; i++) {
			try {XMLHttpRequest = new ActiveXObject(aVersions[i]);}catch (ex) {}//注释：不能alert循环的创建的
		}
	} else if (typeof XMLHttpRequest != "undefined"){
		XMLHttpRequest = new XMLHttpRequest();
	}
			
		return XMLHttpRequest;
}


//图片临时存放路径
function getMrDocLocalPath(){
	return "D:\\MrDocLocal";
}

//扫描仪操作
var Microtek_6240S = {
		"path":function(){

			return "D:\\MICROTEK-6240s";
		},
		"config":function(){
			return this.path()+"\\ScannerCtrl.ini";
		},
		"open":function(){
			var scaner = ocx;
			
			
			<option value="Microtek_6240s">扫描仪-中晶6240s</option>
			<option value="Microtek_XT3500">平板-中晶XT3500</option>
			<option value="Microtek_S8090">扫描仪-中晶S8090</option>
			//扫描类型
			var scanType=$("#ScanerSelect").val();
			if(scanType=='Microtek_S8090'){
				scaner.DSMode(8);//
			}else if(scanType=='Microtek_6240s' || scanType=='Microtek_XT3500'){
				scaner.DSMode(9);//
			}else{
				scaner.DSMode(0);//
			}	
	        
	        var code = scaner.openScanner();
	        
	        if (1 == code){
				Scan.scanerStart = true;
			}else{
				Scan.scanerStart = false;
			}
			
			scaner.SetImageName(getMrDocLocalPath(), "abc", 1, 7);
			
			scaner.BlackBorderRemoval(1);// 注释：默认黑边补白
			
			if(Scan.getFromCookieMD == "Microtek_MEDI-XT3500" || Scan.getFromCookieMD == 
				"Microtek_MEDI1000" || Scan.getFromCookieMD == "Microtek_MEDI1000_NEW" || 
				Scan.getFromCookieMD == "Microtek_6240S" || Scan.getFromCookieMD == "Microtek_6240S_NEW"){
				// 注释：add at 2015-12-09，否则上传bmp格式太大，上传不了
				scaner.ImageFormat = 2;//jpg  0 bmp 2 tif 3 multitif 4 pdf 5 multipdf
				//scaner.CompressionRate = 20;//注释：压缩质量
				scaner.TiffCompressType = 1; //注释：Tiff压缩  1 JPG压缩  2 G4压缩
				//1：jpeg压缩（可以设置CompressionRate改变jpeg压缩的Tiff图像的压缩率，只针对GRAY 和RGB图像）
				//2：Group4 FAX 压缩（只针对BW图像）。
				
				if(Scan.getFromCookieMD == "Microtek_6240S_NEW" || Scan.getFromCookieMD == "Microtek_MEDI1000_NEW"){
					scaner.SetScanThreshold(50);//注释：黑白阈值 浅 10 <-- 130 --> 250 深  默认128
				}else if(Scan.getFromCookieMD == "Microtek_6240S_DEEP"){
					scaner.SetScanThreshold(30);//注释：黑白阈值 浅 10 <-- 130 --> 250 深  默认128
				}else{
					scaner.SetScanThreshold(130);//注释：黑白阈值 浅 10 <-- 130 --> 250 深  默认128
				}
			}
			// ["0","平板"],
			// ["1","ADF单面"],
			// ["2","ADF双面"]
			if(Scan.getFromCookieMD == "Microtek_S8090_RGB"){// 注释：彩色单页扫，jpg格式存储小，tif格式上传不了
//				scaner.SetScanSourceType(1);
				scaner.ImageFormat = 1;//jpg
				scaner.CompressionRate = 20;//
			}else if(Scan.getFromCookieMD == "Microtek_S8090"){
//				scaner.SetScanSourceType(2);
				scaner.ImageFormat = 2;//tif
				scaner.TiffCompressType = 2;
			}else if(Scan.getFromCookieMD == "Microtek_6240S_NEW"){
				scaner.ScanSourceType = 2;
			}else if(Scan.getFromCookieMD == "Microtek_6240S" || Scan.getFromCookieMD == "Microtek_6240S_DEEP"){
				scaner.SetScanImageLayout(0,0,9.39,12.69);//A4
			}
			scaner.ImageFormat = 1;//jpg
			scaner.SetScanImageLayout(0,0,9.39,12.69);
			return code;
		},
		"close":function(){
			var scaner = ocx;
			scaner.CancelXfers();
			scaner.CloseScanner();
		},
		"cancel":function(){
			ocx.CancelXfers();
			alert("本次扫描已中止。");
		},
		
		"scans":function(){
			var scaner = ScanOcx;
			
			scaner.Scan(-1,0);// 连扫
		
			return "scanerReturnValue";
		},
		"scan":function(scanType){
			var scaner = ocx;
			
			if (scanType == 1) {
				scaner.Scan(1, 0);
			//连扫
			} else {
				scaner.Scan(-1, 0);
			}
		},
		"update_abandon":function(){
			//this.update();
		},
		"startScan":function(bSuccess){
			
			///*
			if (bSuccess == 1){
				//获取本地扫描图片路径
				var imagePath = ocx.GetCurrentScanImagePath();
				//alert("扫描图片路径:"+imagePath);
				var result = uploadPhotoImg(imagePath);
				if(result.ret=="success"){
					//this.scanImgArr.push(result.fileName);
					if(isUseful(result.fileName)){
						var basePath=$("#basePath").val();
						var firstGuid=$("#firstGuid").val();
						var picHostPath = $("#picHostPath").val();
						var scanFileSize=$("#scanFileSize").val();
						scanFileSize=parseInt(scanFileSize)+2;
						//alert(scanFileSize);
						$.ajax({
							type:"post",
							url:basePath+"/scan/uploadScanImgs",
							data:{firstGuid:firstGuid,scanImage:result.fileName},
							success:function(data){
								//Microsoft_Scan.scanImgArr=[];
								 if(data.success){
									 var scanFile=data.data[0];
									 var url=picHostPath+scanFile.fileUrl+scanFile.fileName;
									// layer.alert("li"+scanFileSize,{icon:1});
									//alert(url+"fileHash="+scanFile.fileHash+"--fileName="+scanFile.fileName+"--fileUrl="+scanFile.fileUrl);
									 var html="<li  fileUrl='"+scanFile.fileUrl+"' fileName='"+scanFile.fileName+"' fileHash='"+scanFile.fileHash+"' >"+
												"<a id='li"+scanFileSize+"' fileUrl='"+scanFile.fileUrl+"' fileName='"+scanFile.fileName+"' class='imgActive' href='#' onclick='test(this)'>"+
												"<span class='close' onclick='del(this)'>x</span>" +
												"<img src='"+url+"' alt='' />"+
												"</a>"
											"</li>";
									$("#MrDocViewOrBoardUl").prepend(html);
									//alert($("#MrDocViewOrBoardUl").html());
									$("#scanFileSize").val(scanFileSize);
								 }else{
									 layer.alert(data.msg,{icon:1});
								 }
							}
						});
					}
				}
			}else{
				scaner.CancelXfers();
				layer.alert("此页文件扫描未成功，请重新扫描！",{icon:0});
			}
			
		},
		"update":function(){
			var scaner = ocx;
			var imagePath = scaner.GetCurrentScanImagePath();
	  		if (isUse(imagePath)){
				var map = uploading(imagePath);
				uploadImage(map);
	  		}
		}
};



var Microsoft_Scan = {
	// 扫描信息图片路径数据存放集合
	scanImgPath:"",
	scanOpenStatus:false,
	// 开启扫描仪
	openScaner : function() {
		//扫描类型
		var scanType=$("#ScanerSelect").val();
		
		
		
		var scaner = ocx;
		
		//扫描仪6240s和平板XT3500的DSMode为9
		if(scanType=='Microtek_6240s' || scanType=='Microtek_XT3500'){
			scaner.DSMode(9);
		//告诉扫描仪S8090的DSMode为8
		}else if(scanType=='Microtek_S8090'){
			scaner.DSMode(8);
		}else{
			scaner.DSMode(0);
		}
		//Long IsScannerOpen()
		//说明：
		//返回值
		//1：扫描仪已打开。
		//0：扫描仪未打开。
		//alert(scaner.GetState());
		var openStatus = scaner.openScanner();
		if (openStatus != 1) {
			var errorCode = scaner.GetErrorCode();
			this.scanOpenStatus=false;
			layer.alert("扫描仪开启失败!错误代码:" + errorCode,{icon:0});
		}
	
		
		scaner.SetImageName(this.tempImgFile, "0", 1, 7);
		// 去钉孔
		scaner.PunchHoleRemoval(1);
		// 自动纠偏
		scaner.AutoDeskew(1);
		// 黑边补白
		scaner.BlackBorderRemoval(1);// 注释：默认黑边补白
		// 文件格式,可以为下面的几个值:
		// 0:bmp
		// 1:jpg
		// 2.单页tif
		// 3.多页tif
		// 4.单页pdf
		// 5.多页pdf
		// 6.可检索的单页pdf，需要支持OCR识别。
		// 7.可检索的多页pdf，需要支持OCR识别。
		scaner.ImageFormat = 1;
		// 扫描仪类型
		// 0 Flatbed 平板扫描仪
		// 1 ADF
		// 2 ADF duplex
		var scanType=$("#ScanerSelect").val();
		// 扫描仪类型
		// 0 Flatbed 平板扫描仪
		// 1 ADF
		// 2 ADF duplex
		if(scanType=='Microtek_6240s' || scanType=='Microtek_S8090' ){
			scaner.ScanSourceType = 1;
			scaner.SetScanImageLayout(0,0,9.39,12.69);//A4
			scaner.SetScanThreshold(130);
		//0 Flatbed 平板扫描仪	
		}else if(scanType=='Microtek_XT3500'){
			scaner.ScanSourceType = 0;
			scaner.SetScanImageLayout(0,0,9.39,12.69);//A4
			scaner.SetScanThreshold(130);
		}else{
			scaner.ScanSourceType = 1;
		}
		
		
		
	},
	// 关闭扫描仪
	closeScaner : function() {
		var scaner = ocx;
		scaner.CancelXfers();
		scaner.CloseScanner();
	},
	// 打开UI界面设置扫描仪
	settingScaner : function() {
		var scaner = ocx;
		var scanType=$("#ScanerSelect").val();
		//扫描仪6240s和平板XT3500的DSMode为9
		if(scanType=='Microtek_6240s' || scanType=='Microtek_XT3500'){
			scaner.DSMode(9);
		//告诉扫描仪S8090的DSMode为8
		}else if(scanType=='Microtek_S8090'){
			scaner.DSMode(8);
		}else{
			scaner.DSMode(0);
		}
		var openStatus = scaner.openScanner();
		scaner.ShowUISettings();
	},
	// 单扫
	startScan : function(scanType) {
		var scaner = ocx;
		var scanStatus=0;
		// 单扫
		if (scanType == 1) {
			scanStatus=scaner.Scan(1, 0);
		//连扫
		} else {
			scanStatus=scaner.Scan(-1, 0);
		}
		return scanStatus;

	},
	// 取消扫描
	cancleScan : function() {
		var scaner = ocx;
		scaner.CancelXfers();
	},
	//上传本地扫描图片到服务器
	uploadLocalImg:function(bSuccess){
		var scaner = ocx;
		if (bSuccess == 1){
			//获取本地扫描图片路径
			var imagePath = scaner.GetCurrentScanImagePath();
			//alert("扫描图片路径:"+imagePath);
			var result = uploadPhotoImg(imagePath);
			if(result.ret=="success"){
				//this.scanImgArr.push(result.fileName);
				if(isUseful(result.fileName)){
					var basePath=$("#basePath").val();
					var firstGuid=$("#firstGuid").val();
					var picHostPath = $("#picHostPath").val();
					var scanFileSize=$("#scanFileSize").val();
					scanFileSize=parseInt(scanFileSize)+2;
					//alert(scanFileSize);
					$.ajax({
						type:"post",
						url:basePath+"/scan/uploadScanImgs",
						data:{firstGuid:firstGuid,scanImage:result.fileName},
						success:function(data){
							//Microsoft_Scan.scanImgArr=[];
							 if(data.success){
								 var scanFile=data.data[0];
								 var url=picHostPath+scanFile.fileUrl+scanFile.fileName;
								// layer.alert("li"+scanFileSize,{icon:1});
								//alert(url+"fileHash="+scanFile.fileHash+"--fileName="+scanFile.fileName+"--fileUrl="+scanFile.fileUrl);
								 var html="<li  fileUrl='"+scanFile.fileUrl+"' fileName='"+scanFile.fileName+"' fileHash='"+scanFile.fileHash+"' >"+
											"<a id='li"+scanFileSize+"' fileUrl='"+scanFile.fileUrl+"' fileName='"+scanFile.fileName+"' class='imgActive' href='#' onclick='test(this)'>"+
											"<span class='close' onclick='del(this)'>x</span>" +
											"<img src='"+url+"' alt='' />"+
											"</a>"
										"</li>";
								$("#MrDocViewOrBoardUl").prepend(html);
								$("#scanFileSize").val(scanFileSize);
							 }else{
								 layer.alert(data.msg,{icon:1});
							 }
						}
					});
				}
			}
		}else{
			scaner.CancelXfers();
			layer.alert("此页文件扫描未成功，请重新扫描！",{icon:0});
		}
	},
	// 扫描临时文件生成路径
	tempImgFile : "D:\\MrLocal",
	// 删除扫描生成临时文件夹内容
	deleteTempImgs : function() {
		var fileSystemObject = new ActiveXObject("Scripting.FileSystemObject");
		var fileSystem = fileSystemObject.GetFolder(this.tempImgFile);
		var enumFiles = new Enumerator(fileSystem.files);
		for (; !enumFiles.atEnd(); enumFiles.moveNext()) {
			enumFiles.item().Delete();
		}
	}
}


//开启扫描仪
function getScanerOpenInfo(){

	alert(ocx.getState());
	if(parseInt(ocx.getState())<4){
		alert("开启扫描仪");
		var initScanReturnValue = Microtek_6240S.open();
	}
	

	
	return initScanReturnValue;
}


function scanerSaomiao(type){
	
	//删除临时文件目录
	//1.删除上次扫描生成的临时文件
	Microsoft_Scan.deleteTempImgs();
	
	//开启扫描仪
	getScanerOpenInfo();
	
	//注释：此处可能是调用扫描仪扫描
	var map = Microtek_6240S.scan(type);
	
	
	scaner.CancelXfers();
	scaner.CloseScanner();
	
};

//扫描
function scan(scanType){
	//1.删除上次扫描生成的临时文件
	Microsoft_Scan.deleteTempImgs();
	//清空存放扫描信息数组
	Microsoft_Scan.scanImgArr=[];
	//2.开启扫描仪
	//if(!Microsoft_Scan.scanOpenStatus){
		ocx.getState
		Microsoft_Scan.openScaner();
	//}
	
	//3.配置扫描仪
	//Microsoft_Scan.init();
	//4.开始扫描
     Microsoft_Scan.startScan(scanType);
     
     Microsoft_Scan.closeScaner();
	//扫描成功为1
	if(scanStatus==1){
		if(Microsoft_Scan.scanImgArr.length>0){
			var basePath=$("#basePath").val();
			var firstGuid=$("#firstGuid").val();
			console.log(Microsoft_Scan.scanImgArr.toString());

		  
			$.ajax({
				type:"post",
				url:basePath+"/scan/uploadScanImgs",
				data:{firstGuid:firstGuid,scanImageList:Microsoft_Scan.scanImgArr.toString()},
				success:function(data){
					Microsoft_Scan.scanImgArr=[];
					 if(data.success){

						window.location.href=basePath+"/scan/searchScan?firstGuid="+firstGuid;
					 }else{
						 alert(data.msg);
					 }
				}
			});
			Microsoft_Scan.scanImgArr=[];
			
		}else{
			Microsoft_Scan.scanImgArr=[];
			alert("扫描数据为空,请重新扫描!");
		}
		
	}else{
		alert("扫描失败!错误代码:+"+ocx.GetErrorCode());
	}
}



//将临时文件上传至服务器
function uploadPhotoImg(imagePath){
	var basePath=$("#basePath").val();
	var firstGuid=$("#firstGuid").val();
	//var fileName = imagePath
			
	adoStream = new ActiveXObject("ADODB.Stream");
	adoStream.Mode = 3;//read write
			
	adoStream.Open();
	adoStream.Type = 1;
		   	
	var fileType = imagePath.substring(imagePath.lastIndexOf(".")+1);
	var upOneURL = basePath+"/upload/uploadLocalImg";
	adohttp = getXMLHttpRequest();
	adohttp.open('post', upOneURL, false);
	adohttp.setRequestHeader('-fileType',fileType);
	adohttp.setRequestHeader('-firstGuid',firstGuid);//Scan.MrId
			
			
	adohttp.setRequestHeader('-pageOneLocalPath',imagePath.replace(/\\/g,"/"));
	adohttp.setRequestHeader('Content-Type', 'application/x- www-form-urlencoded');

		   	
	adoStream.LoadFromFile(imagePath);
			
			
	var fileSize = fileSystemObject.GetFile(imagePath).Size;
	var adoStreamSize = adoStream.Size;
			
	if (fileSize != adoStreamSize || fileSize < 3584 || adoStreamSize < 3584){
		adoStream.Close();////
		adoStream = null;
		adohttp = null;
		return "noUp";
	}
			
	adohttp.setRequestHeader("Content-Length",adoStream.Size);
			
	adohttp.send(adoStream.Read(adoStream.Size));
	//返回数据
	var result = JSON.parse(adohttp.responseText);
		   
		   	
	adoStream.Close();////
	adoStream = null;
		   	
	adohttp = null;
		   	
	return result;
}
*/